//
//  KLCurrencyService.h
//  KLCurrency
//
//  Created by apple on 2017/12/28.
//  Copyright © 2017年 bonc. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "KLCurrencyEntity.h"
#import "KLCurrencyGroup.h"

@interface KLCurrencyService : NSObject

+ (dispatch_queue_t)serviceQueue;

//提供同步异步方法，逻辑使用需非常谨慎，由于数据量小，部分区域暂不使用异步

//*********plist op **********
/**
 *存入默认主界面货币abb
 */
+ (BOOL)saveDefaultMainCurrencies;
/**
 *存入当前主界面货币abb
 */
+ (BOOL)saveMainCurrencies:(NSArray <NSString *>*)abbs;
+ (void)saveMainCurrencies:(NSArray <NSString *>*)abbs completion:(void (^)(void))completionHandler failure:(void (^)(NSString *))failureHandler;
/**
 *读取当前主界面货币abb
 */
+ (NSArray <NSString *>*)getMainCurrencies;

/**
 *存入默认主界面货币汇率字典 2017-12-01获取的数据
 */
+ (BOOL)saveDefaultExchangeRateDictionary;
/**
 *存入当前货币字典
 */
+ (BOOL)saveExchangeRateDictionary:(NSDictionary *)rateDictionary;
+ (void)saveExchangeRateDictionary:(NSDictionary *)rateDictionary completion:(void (^)(void))completionHandler failure:(void (^)(NSString *))failureHandler;
/**
 *读取当前货币字典
 */
+ (NSDictionary *)getExchangeRateDictionary;

//*********db op *************
//初次导入默认货币数据
+ (long long)importDefaultCurrencies:(NSArray <KLCurrencyEntity *>*)currencies;
+ (void)importDefaultCurrencies:(NSArray <KLCurrencyEntity *>*)currencies completion:(void (^)(long long))completionHandler failure:(void (^)(NSString *))failureHandler;
//获取全部货币数量
+ (long long)getCountOfAllCurrencyEntities;
+ (void)getCountOfAllCurrencyEntitiesWithCompletion:(void (^)(long long))completionHandler failure:(void (^)(NSString *))failureHandler;
//获取主界面四个数据信息
+ (NSArray<KLCurrencyEntity *> *)getMainCurrencyEntities;
+ (void)getMainCurrencyEntitiesWithCompletion:(void (^)(NSArray<KLCurrencyEntity *> *))completionHandler failure:(void (^)(NSString *))failureHandler;
//获取常用货币队列
+ (NSArray<KLCurrencyEntity *> *)getCommonCurrencyEntities;
+ (void)getCommonCurrencyEntitiesWithCompletion:(void (^)(NSArray<KLCurrencyEntity *> *))completionHandler failure:(void (^)(NSString *))failureHandler;
//获取所有货币信息
+ (NSArray<KLCurrencyEntity *> *)getAllCurrencyEntities;
+ (void)getAllCurrencyEntitiesWithCompletion:(void (^)(NSArray<KLCurrencyEntity *> *))completionHandler failure:(void (^)(NSString *))failureHandler;
//获取所有货币分组数据
+ (NSArray<KLCurrencyGroup *> *)getAllCurrencyGroups;
+ (void)getAllCurrencyGroupsWithCompletion:(void (^)(NSArray<KLCurrencyGroup *> *))completionHandler failure:(void (^)(NSString *))failureHandler;
//获取所有搜索结果
+ (NSArray<KLCurrencyEntity *> *)getFilteredCurrencyEntitiesWithSearchText:(NSString *)text;
+ (void)getFilteredCurrencyEntitiesWithSearchText:(NSString *)text completion:(void (^)(NSArray<KLCurrencyEntity *> *))completionHandler failure:(void (^)(NSString *))failureHandler;
//更新主界面货币+同时将选中货币添加为常用货币
+ (BOOL)convertOldMainCurrency:(KLCurrencyEntity *)oldMainCurrency toNewMainCurrency:(KLCurrencyEntity *)newMainCurrency;
+ (void)convertOldMainCurrency:(KLCurrencyEntity *)oldMainCurrency toNewMainCurrency:(KLCurrencyEntity *)newMainCurrency completion:(void (^)(void))completionHandler failure:(void (^)(NSString *))failureHandler;
//移除某个常用货币
+ (BOOL)deleteCommonCurrency:(KLCurrencyEntity *)currency;
+ (void)deleteCommonCurrency:(KLCurrencyEntity *)currency completion:(void (^)(void))completionHandler failure:(void (^)(NSString *))failureHandler;
//更新本地货币
+ (BOOL)updateLocalCurrencyWithLocation:(NSString *)location;
//获取本地货币abbr
+ (NSString *)getLocalCurrencyAbbr;

@end
